package com.lanyan.system.controller.system;

import java.math.BigDecimal;
import java.util.List;
import java.util.Date;
import javax.servlet.http.HttpServletResponse;

import com.lanyan.system.service.IAccountService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lanyan.common.annotation.Log;
import com.lanyan.common.core.controller.BaseController;
import com.lanyan.common.core.domain.AjaxResult;
import com.lanyan.common.enums.BusinessType;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import com.lanyan.system.domain.Pay;
import com.lanyan.system.service.IPayService;
import com.lanyan.common.utils.poi.ExcelUtil;
import com.lanyan.common.core.page.TableDataInfo;

/**
 * 用户支付Controller
 *
 * @author lanyan
 * @date 2024-11-26
 */
@RestController
@RequestMapping("/system/pay")
public class PayController extends BaseController
{
    @Autowired
    private IPayService payService;
    @Autowired
    private IAccountService accountService;

    /**
     * 查询用户支付列表
     */
    @PreAuthorize("@ss.hasPermi('system:pay:list')")
    @GetMapping("/list")
    @ApiImplicitParams({
          @ApiImplicitParam(name = "createBy", value = "创建者", dataType = "String", dataTypeClass = String.class),
          @ApiImplicitParam(name = "createTime", value = "创建时间", dataType = "Date", dataTypeClass = Date.class),
          @ApiImplicitParam(name = "updateBy", value = "更新者", dataType = "String", dataTypeClass = String.class),
          @ApiImplicitParam(name = "updateTime", value = "更新时间", dataType = "Date", dataTypeClass = Date.class),
          @ApiImplicitParam(name = "remark", value = "备注", dataType = "String", dataTypeClass = String.class),
          @ApiImplicitParam(name = "accountId", value = "所属用户", dataType = "Long", dataTypeClass = Long.class),
          @ApiImplicitParam(name = "money", value = "支付金额", dataType = "BigDecimal", dataTypeClass = BigDecimal.class),
          @ApiImplicitParam(name = "vipId", value = "vip主键", dataType = "Long", dataTypeClass = Long.class),
          @ApiImplicitParam(name = "payNo", value = "支付编号", dataType = "String", dataTypeClass = String.class),
          @ApiImplicitParam(name = "pageNum", value = "第几页", dataType = "int", dataTypeClass = int.class),
          @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", dataTypeClass = int.class),

    })
    public TableDataInfo list(Pay pay)
    {
        startPage();
        List<Pay> list = payService.selectPayList(pay);
        for (Pay item : list) {
            item.setAccount(accountService.getById(item.getAccountId()));
        }
        return getDataTable(list);
    }

    /**
     * 导出用户支付列表
     */
    @PreAuthorize("@ss.hasPermi('system:pay:export')")
    @Log(title = "用户支付", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Pay pay)
    {
        List<Pay> list = payService.selectPayList(pay);
        ExcelUtil<Pay> util = new ExcelUtil<Pay>(Pay.class);
        util.exportExcel(response, list, "用户支付数据");
    }

    /**
     * 获取用户支付详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:pay:query')")
    @GetMapping(value = "/{payId}")
    public AjaxResult getInfo(@PathVariable("payId") Long payId)
    {
        return success(payService.selectPayByPayId(payId));
    }

    /**
     * 新增用户支付
     */
    @PreAuthorize("@ss.hasPermi('system:pay:add')")
    @Log(title = "用户支付", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiImplicitParams({
                    @ApiImplicitParam(name = "createBy", value = "创建者", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "createTime", value = "创建时间", dataType = "Date", dataTypeClass = Date.class),
                    @ApiImplicitParam(name = "updateBy", value = "更新者", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "updateTime", value = "更新时间", dataType = "Date", dataTypeClass = Date.class),
                    @ApiImplicitParam(name = "remark", value = "备注", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "accountId", value = "所属用户", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "money", value = "支付金额", dataType = "BigDecimal", dataTypeClass = BigDecimal.class),
                    @ApiImplicitParam(name = "vipId", value = "vip主键", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "payNo", value = "支付编号", dataType = "String", dataTypeClass = String.class),
    })
    public AjaxResult add(@RequestBody Pay pay)
    {
        return toAjax(payService.insertPay(pay));
    }

    /**
     * 修改用户支付
     */
    @PreAuthorize("@ss.hasPermi('system:pay:edit')")
    @Log(title = "用户支付", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiImplicitParams({
                    @ApiImplicitParam(name = "createBy", value = "创建者", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "createTime", value = "创建时间", dataType = "Date", dataTypeClass = Date.class),
                    @ApiImplicitParam(name = "updateBy", value = "更新者", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "updateTime", value = "更新时间", dataType = "Date", dataTypeClass = Date.class),
                    @ApiImplicitParam(name = "remark", value = "备注", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "accountId", value = "所属用户", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "money", value = "支付金额", dataType = "BigDecimal", dataTypeClass = BigDecimal.class),
                    @ApiImplicitParam(name = "vipId", value = "vip主键", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "payNo", value = "支付编号", dataType = "String", dataTypeClass = String.class),
    })
    public AjaxResult edit(@RequestBody Pay pay)
    {
        return toAjax(payService.updatePay(pay));
    }

    /**
     * 删除用户支付
     */
    @PreAuthorize("@ss.hasPermi('system:pay:remove')")
    @Log(title = "用户支付", businessType = BusinessType.DELETE)
	@DeleteMapping("/{payIds}")
    public AjaxResult remove(@PathVariable Long[] payIds)
    {
        return toAjax(payService.deletePayByPayIds(payIds));
    }
}
